package com.pdweb.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pdweb.dao.FuncionariosDao;
import com.pdweb.vo.Funcionarios;

/**
 * Servlet implementation class FuncionariosAdicionaServlet
 */
@WebServlet("/FuncionariosAdicionaServlet")
public class FuncionariosAdicionaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FuncionariosAdicionaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doService(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doService(request, response);
		
	}
	
	protected void doService(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
	
		try {

			Funcionarios funcionarios = new Funcionarios();

			funcionarios.setNomeFuncionario(request.getParameter("ST_NOME_FUNC"));
			funcionarios.setSobrenome(request.getParameter("ST_SOBRENOME_FUNC"));
			funcionarios.setNascimento(request.getParameter("DT_NASCIMENTO_FUNC"));
			funcionarios.setPis(request.getParameter("NM_PIS_FUNC"));
			funcionarios.setAdmissao(request.getParameter("DT_ADMISSAO_FUNC"));
			funcionarios.setSalario(Double.parseDouble(request.getParameter("NM_SALARIO_FUNC")));
			funcionarios.setIdTurno(Integer.parseInt(request.getParameter("TURNOS_ID_TURNO_TURN")));
			funcionarios.setIdDivisao(Integer.parseInt(request.getParameter("DIVISOES_ID_DIVISAO_DIV")));
			funcionarios.setIdCargo(Integer.parseInt(request.getParameter("CARGOS_id_cargo_carg")));
			
			funcionarios.setRua(request.getParameter("ST_RUAEND_FUNC"));
			funcionarios.setNumero(Integer.parseInt(request.getParameter("NM_NUMEEND_FUNC")));
			funcionarios.setBairro(request.getParameter("ST_BAIRROEND_FUNC"));
			funcionarios.setCep(Integer.parseInt(request.getParameter("NM_CEP_FUNC")));
			funcionarios.setCidade(request.getParameter("ST_CIDADE_FUNC"));
			funcionarios.setUf(request.getParameter("ST_UF_FUNC"));
			funcionarios.setTelefone(request.getParameter("ST_TELEFONE_FUNC"));
			funcionarios.setCelular(request.getParameter("ST_CELULAR_FUNC"));
			funcionarios.setEmail(request.getParameter("ST_EMAIL_FUNC"));

			FuncionariosDao FuncionariosDao = new FuncionariosDao();

			FuncionariosDao.adicionaFuncionario(funcionarios);
			
			getServletContext().getRequestDispatcher("/FuncionariosExibirServlet").forward(request,response);
			
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
